package com.easy.tool.utils.regular;

import com.easy.tool.anno.BeanDes;
import com.easy.tool.anno.MethodDes;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 高俊
 * @create 2022-03-2022/3/2-10:58
 */
@BeanDes(name = "正则工具",des = "正则匹配工具类")
public class RegularUtils {
    private static Logger logger = Logger.getLogger(RegularUtils.class);

    /**
     * 正则匹配查询
     * @param str       字符串
     * @param pattern   正则表达式
     * @return
     */
    @MethodDes(des = "正则匹配查询",param = {"arg0-> str：需要匹配的字符串","arg1-> pattern：正则表达式"})
    public static String matchRegular(String str,String pattern){
        String result = "";
        Pattern com = Pattern.compile(pattern);
        Matcher m = com.matcher(str);
       if(m.find()){
           result = m.group(0);
       }else {
           logger.warn("正则表达式没有匹配到字符串");
       }
        return result;
    }

}
